<?php
declare(strict_types=1);

namespace app\library\facade;

use Monolog\Registry;

class Logger extends Facade
{
    public static function channel(? string $name = null)
    {
        return \Monolog\Registry::getInstance(strtoupper($name) ?? 'DEFAULT');
    }

    /**
     * 日志记录的协程封装
     * @param string|null $channel
     * @param string $type
     * @param string $message
     * @param array $context
     */
    public static function goRecord(?string $channel, string $type = 'info', string $message = '', array $context = [])
    {
        go(function() use ($channel, $type, $message, $context){
            call_user_func([self::channel($channel), $type], $message, $context);
        });
    }

}